<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 康复处方
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.hospitalId" placeholder="医院ID" class="handle-input mr10" @keyup.enter.native="handleSearch"></el-input>
                <el-select v-model="query.preState" placeholder="训练状态" class="handle-select mr10" @keyup.enter.native="handleSearch">
                    <el-option key="00" label="未使用" value="00"></el-option>
                    <el-option key="01" label="已使用" value="01"></el-option>
                    <el-option key="02" label="已删除" value="02"></el-option>
                </el-select>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                <el-button type="el-button" icon="el-icon-delete" @click="handleReset">重置</el-button>
            </div>
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column prop="ptId" label="患者ID" width="200" align="center"></el-table-column>
                <el-table-column prop="prePtNm" label="姓名" align="center" width="100"></el-table-column>
<!--                <el-table-column prop="prePtAge" label="年龄" align="center" width="80" sortable></el-table-column>-->
<!--                <el-table-column prop="prePtSexText" label="性别" align="center" width="80"></el-table-column>-->
                <el-table-column prop="preTherape" label="治疗师" align="center" width="80"></el-table-column>
                <el-table-column prop="preId" label="处方ID" width="200" align="center"></el-table-column>
                <el-table-column prop="preStateText" label="训练状态" align="center" width="80"></el-table-column>
                <el-table-column  label="训练时长/分钟" align="center" width="120">
                    <template slot-scope="scope">{{scope.row.preDuration/60}}</template>
                </el-table-column>
                <el-table-column prop="preTimes" label="应训练次数" align="center" width="80"></el-table-column>
                <el-table-column prop="preOldTimes" label="已训练次数" align="center" width="80"></el-table-column>
                <el-table-column prop="preIstTm" label="创建时间" width="120" align="center" sortable></el-table-column>
                <el-table-column prop="preCrtBy" label="创建人" width="80" align="center"></el-table-column>
                <el-table-column prop="hospitalId" label="医院ID" align="center" width="200"></el-table-column>
                <el-table-column prop="hospitalSystemId" label="机器编号" align="center"></el-table-column>
                <el-table-column label="操作" width="100" align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-thumb"
                                @click="handlePrescription(scope.$index, scope.row)"
                        >查看详情</el-button>
<!--                        <el-button v-if="roleIds !=='system'"-->
<!--                                type="text"-->
<!--                                icon="el-icon-football"-->
<!--                                @click="handleEdit(scope.$index, scope.row)"-->
<!--                        >康复训练</el-button>-->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="total, prev, pager, next"
                        :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
        <!-- 前往训练弹出框 -->
        <el-dialog title="实时训练信息" :visible.sync="goTrainVisible" width="60%" :before-close="closeTrain">
            <el-row style="margin-top: 10px">
                <el-col :span="8" style="margin-left: 15px">
                    <span style="font-size: 18px;margin-bottom: 10px">患者ID： {{this.condition.ptId}}</span>
                </el-col>
                <el-col :span="4">
                    <span style="font-size: 18px;margin-bottom: 10px">姓名：{{this.condition.prePtNm}}</span>
                </el-col>
                <el-col :span="4">
                    <span style="font-size: 18px;margin-bottom: 10px">治疗师： {{this.condition.preTherape}}</span>
                </el-col>
                <el-col :span="4">
                    <span style="font-size: 18px;margin-bottom: 10px">剩余训练次数： {{this.condition.preTimes-this.condition.preOldTimes}}</span>
                </el-col>
            </el-row>
            <el-button style="margin-top: 12px" type="primary" @click="startTrain" :disabled="isStartButton">开始</el-button>
            <el-button type="success" @click="stopTrain" :disabled="isStopButton">暂停</el-button>
            <el-button type="success" plain @click="nowTrain" :disabled="isNowButton">继续</el-button>
            <el-button type="warning" plain @click="lastTrain" :disabled="isLastButton">下一个</el-button>
            <el-button type="info" plain @click="endTrain" :disabled="isEndButton">结束</el-button>
            <el-row>
                <el-col :span="10" style="margin-top: 20px">
                    <el-card shadow="hover" style="height:580px;overflow: scroll;overflow-x: hidden;border-color: #bcc7f0">
<!--                        <span>总进度</span>-->
                        <el-row>
                            <el-col :span="10">
                                总进度
                            </el-col>
                            <el-col :span="10">
                                总时间:{{total+'/s'}}
                            </el-col>
                        </el-row>
                        <el-progress v-if="total===0" style="margin-top: 10px" :text-inside="true" :stroke-width="18" :format="format" :percentage="0"></el-progress>
                        <el-progress v-if="total!==0" style="margin-top: 10px" :text-inside="true" :stroke-width="18" :format="format" :percentage="current/total*100"></el-progress>
                        <div v-for="(v,i) in preList">
                            <span style="color: #5ec211;font-size: 16px">处方{{i+1}}</span>
                            <el-card  shadow="always"  height="60" style="border-color: #bcc7f0;margin-top: 5px">
                                <!--卡片中的内容-->
                                <el-form ref="preform" :model="preform" label-width="100px">
                                    <el-row>
                                        <el-col :span="13">
                                            <el-form-item label="运动类型" prop="preActionType" >
                                                <el-input readonly v-model="preList[i].preActionTypeText" style="width: 100%">
                                                </el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="13">
                                            <el-form-item label="是否电刺激" prop="preActionElectricalStatus" >
                                                <el-input readonly v-model="preList[i].preActionElectricalStatusText" style="width: 100%"></el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="13" v-if="preList[i].preActionElectricalStatus=='01'">
                                            <el-form-item  label="刺激类型" prop="preActionElectrical" >
                                                <el-input readonly v-model="preList[i].preActionElectricalText" style="width: 100%"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row v-if="preList[i].preActionElectricalStatus=='01'">
                                        <el-col :span="18" v-if="preList[i].isFinished ==undefined">
                                            <el-form-item    label="幅度值" prop="preActionAmplitude" >
                                                <el-button disabled type="success" plain  @click="downPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">-</el-button>
                                                <el-input  readonly v-model="preList[i].preActionAmplitude" style="margin-left: 5px;width: 30%"></el-input>
                                                <el-button disabled type="success" plain style="margin-left: 5px" @click="upPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">+</el-button>
                                            </el-form-item>
                                        </el-col>
                                        <!--幅度值分为三种 1.已结束运动的，+ -不可点击 2.正在运行的 + - 可以点击  3.未开始的 + - 不可点击  幅度值 0~99-->
                                        <!--1.已结束-->
                                        <el-col :span="18" v-if="preList[i].isFinished!==undefined && preList[i].isFinished==true">
                                            <el-form-item    label="幅度值" prop="preActionAmplitude" >
                                                <el-button disabled type="success" plain  @click="downPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">-</el-button>
                                                <el-input  readonly v-model="preList[i].preActionAmplitude" style="margin-left: 5px;width: 30%" ref="PreAmp"></el-input>
                                                <el-button disabled type="success" plain style="margin-left: 5px" @click="upPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">+</el-button>
                                            </el-form-item>
                                        </el-col>
                                        <!--2.正在运行-->
                                        <el-col :span="18" v-if="preList[i].isFinished==false && preList[i].current !==0 && preList[i].current<preList[i].total">
                                            <el-form-item    label="幅度值" prop="preActionAmplitude" >
                                                <el-button  type="success" plain  @click="downPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">-</el-button>
                                                <el-input  readonly v-model="preList[i].preActionAmplitude" style="margin-left: 5px;width: 30%"  ref="PreAmp"></el-input>
                                                <el-button type="success" plain style="margin-left: 5px" @click="upPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">+</el-button>
                                            </el-form-item>
                                        </el-col>
                                        <!--3.还未进行-->
                                        <el-col :span="18" v-if="preList[i].isFinished!==undefined && preList[i].isFinished==false && preList[i].current==0">
                                            <el-form-item    label="幅度值" prop="preActionAmplitude" >
                                                <el-button disabled type="success" plain  @click="downPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">-</el-button>
                                                <el-input  readonly v-model="preList[i].preActionAmplitude" style="margin-left: 5px;width: 30%"  ref="PreAmp"></el-input>
                                                <el-button disabled type="success" plain style="margin-left: 5px" @click="upPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">+</el-button>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row v-if="preList[i].preActionType=='01'">
                                        <el-col :span="12">
                                            <el-form-item  label="左脚速度" prop="preActionLeftSpeed" >
                                                <el-input readonly type="number" v-model="preList[i].preActionLeftSpeed"  :min="1" style="width: 100%"></el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item   label="右脚速度" prop="preActionRightSpeed" >
                                                <el-input readonly type="number" v-model="preList[i].preActionRightSpeed" :min="1" style="width: 100%"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="17">
                                            <el-form-item  label="痉挛值" prop="preActionSpasm" >
                                                <el-input readonly type="number" v-model="preList[i].preActionSpasm" :min="1" :max="3" style="width: 60%" ></el-input> 级(1,2,3)
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="17">
                                            <el-form-item  label="运动时间" prop="preActionTime" >
                                                <el-input readonly type="number" v-model="preList[i].preActionTime/60" :min="1" style="width: 60%"></el-input> 分钟
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                                <!--已结束 完成-->
                                <el-progress v-if="preList[i].isFinished==true" :percentage="100" :show-text="showText" ></el-progress>
                                <!--正在运行-->
                                <el-progress v-if="preList[i].isFinished==false && preList[i].current !==0 && preList[i].current<preList[i].total" :show-text="showText" :percentage="preList[i].current/preList[i].total*100"></el-progress>
<!--                                <el-progress v-if="preList[i].isFinished==false && preList[i].current !==0 && preList[i].current<preList[i].total" :percentage="(((preList[i].current/preList[i].total)*100)+'').substring(0,(((preList[i].current/preList[i].total)*100)+'').indexOf('.'))" ></el-progress>-->
                                <!--还未进行 -->
                                <el-progress v-if="preList[i].isFinished==false && preList[i].current==0" :show-text="showText" :percentage="0" ></el-progress>
                                <!--初始化-->
                                <el-progress v-if="preList[i].isFinished==undefined && preList[i].current==undefined && preList[i].total==undefined " :show-text="showText" :percentage="0" ></el-progress>
                            </el-card>
                        </div>
                    </el-card>
                </el-col>
                <el-col :span="10" style="margin-left: 40px">
                    <el-row>
                        <el-col :span="8">
<!--                            <schart class="schart" canvasId="line"  :options="leftOptions"></schart>-->
                            <div id="myleftChart" style="width:550px;height: 300px" v-if="showDiv"></div>
<!--                            <chart :options="leftOptions"></chart>-->
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
<!--                            <schart  class="schart" canvasId="line2"   :options="rigthOptions"></schart>-->
                            <div id="myrigthChart" style="width:550px;height: 300px" v-if="showDiv" ></div>
                        </el-col>
                    </el-row>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="closeTrain">关 闭</el-button>
            </span>
        </el-dialog>
        <!-- 查看康复训练弹出框 -->
        <el-dialog title="处方详情" :visible.sync="seeVisible" width="30%" :before-close="seeColse">
            <div style="margin-bottom: 10px;">
                <el-form  label-width="70px">
                    <el-row style="margin-top: 10px">
                        <el-col :span="2" style="margin-left: 15px">
                        </el-col>
                        <el-col :span="10">
                            <el-form-item label="治疗师" >
                                <el-input readonly  v-model="preCrtBy"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="训练次数">
                                <el-input readonly type="number" v-model="preTimes"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <el-tabs v-model="editableTabsValue" type="card">
                <el-tab-pane v-if="editableTabs && editableTabs.length >=0"
                             v-for="(item, index) in editableTabs"
                             :key="item.name"
                             :label="item.title"
                             :name="item.name">
                    <component :is="item.content"  v-bind:contentForm="item.contentForm"></component>
                </el-tab-pane>
            </el-tabs>
            <span slot="footer" class="dialog-footer">
                                <el-button @click="seeColse">关 闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import {getPrescriptions, selectBypreId} from '../../../api/prescription/prescription';
    import Schart from "vue-schart";
    import presModel from "../prescription/presModel";
    import {
        goNextAction,
        play,
        resume, sendEleTrainAdd,
        sendEleTrainReduce,
        sendReset,
        startTraining,
        stop,
        stopTrain
    } from "../../../api/train/train";
    export default {
        name: 'role',
        data() {
            return {
                query: {
                    hospitalId: '',
                    preState:'',
                    userAcct:localStorage.getItem('ms_userAcct'),
                    pageIndex: 1,
                    pageSize: 10
                },
                roleIds:localStorage.getItem('ms_roleIds'),
                userAcct: localStorage.getItem('ms_userAcct'),
                tableData: [],
                multipleSelection: [],
                goTrainVisible: false,
                seeVisible:false,
                pageTotal: 0,
                idx: -1,
                id: -1,
                editableTabsValue: '1',
                editableTabs: [],
                preCrtBy:'',//治疗师
                preTimes:0,//次数
                trainData:{
                    preId:"",
                    ptId:''
                },
                isStartButton:false,
                isStopButton:true,
                isNowButton:true,
                isLastButton:true,
                isEndButton:true,
                taskId:'',
                timer:'',
                leftOptions: {},
                leftLabels:[],
                leftData:[],
                rigthOptions: {},
                rigthLabels:[],
                rigthData:[],
                condition:{
                    ptId:'',
                    prePtNm:'',
                    preTherape:'',
                    preOldTimes:'',
                    preTimes:'',
                },
                preList:[],
                form:{},
                preform:{},
                total:0,
                current:0,
                showText:false,
                showDiv:false,
            };
        },
        created() {
            this.getData();
        },
        components:{
            presModel,
            Schart
        },
        methods: {
            // 获取后台数据
            getData() {
                getPrescriptions(this.query).then(res => {
                    if (res.success === true){
                        this.tableData = res.data;
                        this.pageTotal = res.total;
                    } else {
                        this.$message.error("查询失败！");
                        this.tableData = [];
                        this.pageTotal = 0;
                    }
                });
            },
            // 触发搜索按钮
            handleSearch() {
                this.$set(this.query, 'pageIndex', 1);
                this.getData();
            },
            // 触发重置按钮
            handleReset() {
                this.query.hospitalId = "";
                this.query.preState="";
                this.getData();
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            //总进度进度条展示
            format(percentage){
                let result=this.current+'/s';
                return percentage <=100 ? result:'';
            },
           //开始根据处方进行训练
             handleEdit(index, row) {
                if(row.preTimes<=row.preOldTimes){
                    this.$message.error('运动次数已用完');
                    return ;
                }
                 const loading = this.$loading({
                     lock: true,
                     text: '复位中',
                     spinner: 'el-icon-loading',
                     background: 'rgba(0, 0, 0, 0.7)'
                 });
                 sendReset().then(res => {
                     loading.close();
                     if (res.success==true){
                         //根据处方id查询处方记录
                         selectBypreId({preId: row.preId}).then(res => {
                             if (res.success==true){
                                 console.log("----进来了");
                                 this.showDiv=false;
                                 this.preList = res.data.standPrescriptionActionPOJOS;
                                 this.trainData.preId=row.preId;
                                 this.trainData.ptId=row.ptId;
                                 this.isStartButton=false;
                                 this.isStopButton=true;
                                 this.isNowButton=true;
                                 this.isLastButton=true;
                                 this.isEndButton=true;
                                 this.taskId="";
                                 this.timer="";
                                 this.leftLabels=[];
                                 this.leftData=[];
                                 this.leftOptions={};
                                 this.rigthLabels=[];
                                 this.rigthData=[];
                                 this.rigthOptions={};
                                 this.condition.ptId=row.ptId;
                                 this.condition.prePtNm=row.prePtNm;
                                 this.condition.preTherape=row.preTherape;
                                 this.condition.preOldTimes=row.preOldTimes;
                                 this.condition.preTimes=row.preTimes;
                                 this.current=0;
                                 this.total=0;
                                 this.goTrainVisible = true;
                             }else{
                                 this.$message.error('处方查询失败');
                             }
                         });
                     } else {
                         this.$message.error('复位失败');
                         loading.close();
                     }
                 });
            },
            //获取后台数据
            getNewMessage: function() {
                play({taskId:this.taskId}).then(res => {
                    if (res.success==true){
                        if (res.data.isFinished==true){
                            window.clearInterval(this.timer);
                            this.goTrainVisible=false;
                            this.$message.success('结束训练成功');
                        }else{
                            for (let i = 0; i <this.preList.length; i++) {
                                for (let j = 0; j <res.data.actions.length; j++) {
                                    if (this.preList[i].preId==res.data.actions[j].standPrescriptionActionPOJO.preId && this.preList[i].preActionId==res.data.actions[j].standPrescriptionActionPOJO.preActionId){
                                        this.preList[i].isFinished=res.data.actions[j].isFinished;
                                        this.preList[i].current=res.data.actions[j].current;
                                        this.preList[i].total=res.data.actions[j].total;
                                    }
                                };
                            };
                            this.total=res.data.total;
                            this.current=res.data.current;
                            let nowTime="";
                            if (res.data.standPreApmPOJO!==null && res.data.standPreApmPOJO!==undefined && res.data.standPreApmPOJO.paIstTm!==undefined && res.data.standPreApmPOJO.paIstTm !==null && res.data.standPreApmPOJO.paIstTm!=="") {
                            //后台传过来的时间，进行格式化成时分秒
                            nowTime = res.data.standPreApmPOJO.paIstTm.slice(14,19);
                            console.log("nowTime", nowTime);
                            //渲染左侧处方信息
                            //左 右
                            if (this.leftLabels.length>=10){
                                this.leftLabels=this.leftLabels.slice(1,this.leftLabels.length);
                            };
                            this.leftLabels.push(nowTime);
                            if (this.rigthLabels.length>=10){
                                this.rigthLabels=this.rigthLabels.slice(1,this.rigthLabels.length);
                            };
                            this.rigthLabels.push(nowTime);
                            if (this.leftData.length>=10){
                                this.leftData=this.leftData.slice(1, this.leftData.length);
                            };
                            this.leftData.push(res.data.standPreApmPOJO.paLeftAcPos);
                            if (this.rigthData.length>=10){
                                this.rigthData=this.rigthData.slice(1, this.rigthData.length);
                            };
                            this.rigthData.push(res.data.standPreApmPOJO.paRightAcPos);
                            this.leftOptions={
                                title:{
                                    text:'左脚运动位置'
                                },
                                tooltip:{
                                    trigger:'axis',
                                },
                                xAxis:{
                                    data:this.leftLabels,
                                    name: '时间',
                                    splitLine: { // 去除网格区域
                                        show: false,
                                    }
                                },
                                yAxis:{
                                    type:'value',
                                    scale: true,
                                    min:0,
                                    max:100,
                                },
                                series:[{
                                    type:'bar',
                                    itemStyle:{
                                        color:"#3591FF"
                                    },
                                    data: this.leftData
                                }]
                            };
                            this.rigthOptions={
                                title:{
                                    text:'右脚运动位置'
                                },
                                tooltip:{
                                    trigger:'axis',
                                },
                                xAxis:{
                                    data:this.rigthLabels,
                                    name: '时间',
                                    splitLine: { // 去除网格区域
                                        show: false,
                                    }
                                },
                                yAxis:{
                                    type:'value',
                                    scale: true,
                                    min:0,
                                    max:100,
                                },
                                series:[{
                                    type:'bar',
                                    itemStyle:{
                                        color:"#3591FF"
                                    },
                                    data: this.rigthData
                                }]
                                };
                                let myleftChart=this.$echarts.init(document.getElementById('myleftChart'),);
                                myleftChart.setOption(this.leftOptions);
                                let myrigthChart=this.$echarts.init(document.getElementById('myrigthChart'),);
                                myrigthChart.setOption(this.rigthOptions);
                            }
                        }
                    }else{
                        this.$message.error('获取实时位置失败');
                    }
                });
            },
            //开始
            async startTrain(){
                //开始训练
                await  startTraining(this.trainData).then(res => {
                    //开始训练 返回taskId
                    if (res.success == true) {
                        this.$message.success('开始成功');
                        this.showDiv=true;
                        this.isStartButton=true;
                        this.isStopButton=false;
                        this.isLastButton=false;
                        this.isEndButton=false;
                        this.taskId=res.data;
                        //每一秒 调用后台获取位置信息
                        this.timer=window.setInterval(() => {
                            setTimeout(this.getNewMessage(), 0);
                        }, 1000);
                    }else {
                        this.$message.error('开始失败');
                    }
                });
            },
            //暂停
            async stopTrain(){
                window.clearInterval(this.timer);
                this.isStopButton=true;
                this.isNowButton=false;
                await  stopTrain({taskId:this.taskId}).then(res => {
                    if (res.data==1){
                        this.$message.success('暂停成功');
                    }else{
                        this.$message.error('暂停失败');
                    }
                });
            },
            //继续
            async nowTrain(){
                this.isNowButton=true;
                this.isStopButton=false;
                await  resume({taskId:this.taskId}).then(res => {
                    if (res.data==1){
                        this.$message.success('继续成功');
                        window.clearInterval(this.timer);
                        this.timer=window.setInterval(() => {
                            setTimeout(this.getNewMessage(), 0);
                        }, 1000);
                    }else{
                        this.$message.error('继续失败');
                    }
                });
            },
            //下一个
            async lastTrain(){
                window.clearInterval(this.timer);
                await  goNextAction({taskId:this.taskId}).then(res => {
                    if (res.data==1){
                        this.$message.success('下一个成功');
                        this.isStopButton=false;
                        this.isNowButton=true;
                        this.timer=window.setInterval(() => {
                            setTimeout(this.getNewMessage(), 0);
                        }, 1000);
                    }
                });
            },
            //结束
            async endTrain(){
                window.clearInterval(this.timer);
                await  stop({taskId:this.taskId}).then(res => {
                    if (res.success==true){
                        this.$message.success('结束训练成功');
                        window.clearInterval(this.timer);
                        this.goTrainVisible=false;
                        this.taskId="";
                        this.timer="";
                        this.leftOptions={};
                        this.leftLabels=[];
                        this.leftData=[];
                        this.rigthOptions={};
                        this.rigthLabels=[];
                        this.rigthData=[];
                    }else{
                        this.$message.error('结束失败');
                    }
                });
            },
            //关闭实时运动位置弹出框
            closeTrain(){
                this.$confirm('确认关闭？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        if (this.taskId==''){
                            window.clearInterval(this.timer);
                            this.goTrainVisible=false;
                            // location.reload();
                            return;
                        }
                        stop({taskId:this.taskId}).then(res => {
                            if (res.success == true) {
                                window.clearInterval(this.timer);
                                this.$message.success('结束训练成功');
                                this.taskId="";
                                this.timer="";
                                this.leftOptions={};
                                this.leftLabels=[];
                                this.leftData=[];
                                this.rigthOptions={};
                                this.rigthLabels=[];
                                this.rigthData=[];
                                this.goTrainVisible=false;
                            }else{
                                this.$message.error("训练结束失败");
                            }
                        });
                    })
                    .catch(() => {
                        this.$message({
                            message:'已取消操作'
                        });
                    });
            },
            //幅度值 --
            downPreAmp(preId,preActionId,preActionAmplitude,i){
                if (preActionAmplitude<=99 && preActionAmplitude !==0){
                    //发送辐射指令 --
                    sendEleTrainReduce({preId:preId,preActionId:preActionId,preActionAmplitude:preActionAmplitude-1}).then(res => {
                        if (res.success==true){
                            this.$refs.PreAmp.value = preActionAmplitude-1;    // 给有 ref 属性的 input 赋值
                            this.preList[i].preActionAmplitude=preActionAmplitude-1;
                            console.log("幅度值--成功，值：",preActionAmplitude-1);
                        }else{
                            this.$message.error(res.data);
                        }
                    });
                }
            },
            //幅度值 ++
            upPreAmp(preId,preActionId,preActionAmplitude,i){
                console.log("preActionAmplitude--",preActionAmplitude);
                //发送辐射指令 --
                if (preActionAmplitude==undefined || preActionAmplitude ==""){
                    sendEleTrainAdd({preId:preId,preActionId:preActionId,preActionAmplitude:1}).then(res => {
                        if (res.success==true){
                            this.$refs.PreAmp.value=1;
                            this.preList[i].preActionAmplitude=1;
                        }else{
                            this.$message.error(res.data);
                        }
                    });
                }else{
                    if (preActionAmplitude<99){
                        sendEleTrainAdd({preId:preId,preActionId:preActionId,preActionAmplitude:preActionAmplitude+1}).then(res => {
                            if (res.success==true){
                                this.$refs.PreAmp.value = parseInt(preActionAmplitude)+1;    // 给有 ref 属性的 input 赋值
                                this.preList[i].preActionAmplitude=parseInt(preActionAmplitude)+1;
                            }else{
                                this.$message.error(res.data);
                            }
                        });
                    }else {//超过99
                        sendEleTrainAdd({preId:preId,preActionId:preActionId,preActionAmplitude:99}).then(res => {
                            if (res.success==true){
                                this.$refs.PreAmp.value = 99;    // 给有 ref 属性的 input 赋值
                                this.preList[i].preActionAmplitude=99;
                            }else{
                                this.$message.error(res.data);
                            }
                        });
                    }
                }
                console.log("幅度值++成功，值：",this.preList[i].preActionAmplitude);
                // POST /api/stand/training/sendEleTrainAdd
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            },
            //查看弹出框
            handlePrescription(index, row) {
                this.editableTabs=[];
                this.editableTabsValue='1';
                //根据处方id查询处方记录
                selectBypreId({preId: row.preId,hospitalId:row.hospitalId,hospitalSystemId:row.hospitalSystemId}).then(res => {
                    if (res.success==true){
                        for(let i=0;i<res.data.standPrescriptionActionPOJOS.length;i++){
                            res.data.standPrescriptionActionPOJOS[i].preActionTime=res.data.standPrescriptionActionPOJOS[i].preActionTime/60;
                            this.editableTabs.push({
                                title: '训练类型选择',
                                name: res.data.standPrescriptionActionPOJOS[i].preActionSort,
                                content:'presModel',
                                contentForm:res.data.standPrescriptionActionPOJOS[i]
                            });
                        }
                        this.preCrtBy=res.data.preTherape;
                        this.preTimes=parseInt(res.data.preTimes);
                        this.seeVisible = true;
                    }else{
                        this.$message.error('处方查询失败');
                    }
                })
            },
            //关闭查看弹出框
            seeColse(){
                this.$confirm('确认关闭？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        this.seeVisible = false;
                    })
                    .catch(() => {
                        this.$message({
                            message:'已取消操作'
                        });
                    });
            },
        }
    };
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .table {
        width: 100%;
        font-size: 14px;
    }
    .red {
        color: #ff0000;
    }
    .mr10 {
        margin-right: 10px;
    }
    .schart {
        width: 550px;
        height: 300px;
    }
    .content-title {
        clear: both;
        font-weight: 400;
        line-height: 50px;
        margin: 10px 0;
        font-size: 22px;
        color: #1f2f3d;
    }

</style>
